import config from '../config.js'

var comm = {
    setCookie: function(key, value) {
        key = key + config.appTheme
        if (typeof key !== 'undefined' && typeof value !== 'undefined') {
            var exp = new Date()
            exp.setTime(exp.getTime() + 24 * 3600 * 6 * 1000) //这个时间不能长于服务器utils/WxUser/getWxUserInfo的缓存时间
            document.cookie = key + '=' + value + ';expires=' + exp.toGMTString()
        }
    },
    getCookie: function(key) {
        key = key + config.appTheme
        var reg = new RegExp('(^| )' + key + '=([^;]*)(;|$)')
        var arr = document.cookie.match(reg)
        if (arr) {
            return unescape(arr[2])
        } else {
            return null
        }
    }
}
export default comm
